package org.example.warehouse.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import org.example.warehouse.domain.WarehouseStore;
import org.example.warehouse.service.IWarehouseStoreService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓库存储Controller
 *
 * @author 小孟微信：xiaomengcode
 * @date 2024-04-12
 */
@Controller
@RequestMapping("/warehouse/warehouseStore")
public class WarehouseStoreController extends BaseController
{
    private String prefix = "warehouse/warehouseStore";

    @Autowired
    private IWarehouseStoreService warehouseStoreService;

    @GetMapping()
    public String warehouseStore(WarehouseStore warehouseStore,ModelMap mmp)
    {
        mmp.put("warehouseStore", warehouseStore);
        return prefix + "/warehouseStore";
    }

    /**
     * 查询仓库存储列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WarehouseStore warehouseStore)
    {
        startPage();
        List<WarehouseStore> list = warehouseStoreService.selectWarehouseStoreList(warehouseStore);
        return getDataTable(list);
    }

    /**
     * 导出仓库存储列表
     */
    @RequiresPermissions("warehouse:warehouseStore:export")
    @Log(title = "仓库存储", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WarehouseStore warehouseStore)
    {
        List<WarehouseStore> list = warehouseStoreService.selectWarehouseStoreList(warehouseStore);
        ExcelUtil<WarehouseStore> util = new ExcelUtil<WarehouseStore>(WarehouseStore.class);
        return util.exportExcel(list, "仓库存储数据");
    }

    /**
     * 新增仓库存储
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存仓库存储
     */
    @RequiresPermissions("warehouse:warehouseStore:add")
    @Log(title = "仓库存储", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WarehouseStore warehouseStore)
    {
        return toAjax(warehouseStoreService.insertWarehouseStore(warehouseStore));
    }

    /**
     * 修改仓库存储
     */
    @RequiresPermissions("warehouse:warehouseStore:edit")
    @GetMapping("/edit/{warehouseStoreId}")
    public String edit(@PathVariable("warehouseStoreId") Long warehouseStoreId, ModelMap mmap)
    {
        WarehouseStore warehouseStore = warehouseStoreService.selectWarehouseStoreByWarehouseStoreId(warehouseStoreId);
        mmap.put("warehouseStore", warehouseStore);
        return prefix + "/edit";
    }

    /**
     * 修改保存仓库存储
     */
    @RequiresPermissions("warehouse:warehouseStore:edit")
    @Log(title = "仓库存储", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WarehouseStore warehouseStore)
    {
        return toAjax(warehouseStoreService.updateWarehouseStore(warehouseStore));
    }

    /**
     * 删除仓库存储
     */
    @RequiresPermissions("warehouse:warehouseStore:remove")
    @Log(title = "仓库存储", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(warehouseStoreService.deleteWarehouseStoreByWarehouseStoreIds(ids));
    }
}
